home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / filutil / uudx278d.zip / DEFISHX.DIF next >
Text File  |  1993-03-06  |  10KB  |  466 lines

  1. --- ..\uudx\uudx.c    Fri Feb 26 22:22:12 1993
  2. +++ defishx.c    Fri Feb 26 22:16:38 1993
  3. @@ -1,11 +1,11 @@
  4.  /*
  5. - *    uudx - extractor from uuencoded files
  6. + *    defishx - extractor from fishencoded files
  7.   *
  8.   *    Written by AssistantIO
  9.   */
  10.  
  11. -#define    COMMAND        "uudx"
  12. -#define VERSION        "ver. 2.78"
  13. +#define    COMMAND        "defishx"
  14. +#define VERSION        "ver. 0.06"
  15.  
  16.  #include <stdio.h>
  17.  #include <ctype.h>
  18. @@ -130,6 +130,12 @@
  19.  static void uudx(FILE *fh_i);
  20.  static char *jstrupr(char *p);
  21.  static int decode_begin(char *inbuf, int *mode, char *file_name);
  22. +static int xdecode(int type, char *inbuf, char *outbuf);
  23. +static int decode2(char *inbuf, char *outbuf);
  24. +static int decode3(char *inbuf, char *outbuf);
  25. +static void initialize_hash(void);
  26. +static int search_table(int c1, int c2);
  27. +static void *xmalloc(int size);
  28.  static int check_file(char *fname);
  29.  static int file_cmp(char *fname1, char *fname2);
  30.  static int decode(char *ibuf, char *obuf);
  31. @@ -233,6 +239,8 @@
  32.      signal(SIGINT, sig_int_handler);
  33.  #endif
  34.  
  35. +    initialize_hash();
  36. +
  37.      if (optind >= argc && isatty(fileno(stdin)) == 0) {
  38.          fp = stdin;
  39.          fprintf(stderr, "Decoding from %s ...\n",
  40. @@ -329,6 +337,7 @@
  41.      char    *fname, *p, *s;
  42.      int        l, i;
  43.      int        long_line, newline;
  44. +    int        type;
  45.  
  46.  #if MSDOS
  47.      setmode(fileno(fh_i), O_BINARY);
  48. @@ -370,7 +379,7 @@
  49.          if (newline
  50.              && !long_line
  51.              && strncmp(inbuf, "begin", 5) == 0
  52. -            && decode_begin(inbuf, &mode, file_name) > 0) {
  53. +            && (type = decode_begin(inbuf, &mode, file_name)) > 0) {
  54.  
  55.              if (nerror > 1L) {
  56.                  fprintf(stderr, "[%ld] %s\n", line_no - 1, errbuf);
  57. @@ -505,7 +514,7 @@
  58.                     && !tmp_off
  59.                     && newline
  60.                     && !long_line
  61. -                   && (n = decode(inbuf, outbuf)) > 0) {
  62. +                   && (n = xdecode(type, inbuf, outbuf)) > 0) {
  63.  
  64.              if (nerror > 1L) {
  65.                  fprintf(stderr, "[%ld] %s\n", line_no - 1, errbuf);
  66. @@ -580,6 +589,7 @@
  67.  decode_begin(char *inbuf, int *mode, char *file_name)
  68.  {
  69.      char *p;
  70. +    int type;
  71.  
  72.      p = inbuf;
  73.      if (strncmp(p, "begin ", 6) != 0) {
  74. @@ -588,19 +598,33 @@
  75.      p += 6;
  76.      while (*p == ' ') {
  77.          p++;
  78. -    }
  79. -    if (*p < '0' || *p > '7') {
  80. -        return 0;
  81.      }
  82. -    *mode = 0;
  83. -    while (*p >= '0' && *p <= '7') {
  84. -        *mode = *mode * 8 + *p - '0';
  85. +    if (strncmp(p, "4649 ", 5) == 0) {
  86. +        type = 2;
  87. +        *mode = 0644;
  88. +        p += 5;
  89. +    } else if (strncmp(p, "86~ ", 4) == 0) {
  90. +        type = 3;
  91. +        *mode = 0644;
  92. +        p += 4;
  93. +    } else if (strncmp(p, "24~ ", 4) == 0) {
  94. +        type = 2;
  95. +        *mode = 0644;
  96. +        p += 4;
  97. +    } else if (*p >= '0' && *p <= '7') {
  98. +        type = 1;
  99. +        *mode = 0;
  100. +        while (*p >= '0' && *p <= '7') {
  101. +            *mode = *mode * 8 + *p - '0';
  102. +            p++;
  103. +        }
  104. +        if (*p != ' ') {
  105. +            return 0;
  106. +        }
  107.          p++;
  108. -    }
  109. -    if (*p != ' ') {
  110. +    } else {
  111.          return 0;
  112.      }
  113. -    p++;
  114.      while (*p == ' ') {
  115.          p++;
  116.      }
  117. @@ -618,7 +642,323 @@
  118.              return 0;
  119.          }
  120.      }
  121. -    return 1;
  122. +    return type;
  123. +}
  124. +
  125. +static int
  126. +xdecode(int type, char *inbuf, char *outbuf)
  127. +{
  128. +    int ret;
  129. +
  130. +    switch (type) {
  131. +    case 1:
  132. +        ret = decode(inbuf, outbuf);
  133. +        break;
  134. +    case 2:
  135. +        ret = decode2(inbuf, outbuf);
  136. +        break;
  137. +    case 3:
  138. +        ret = decode3(inbuf, outbuf);
  139. +        break;
  140. +    default:
  141. +        fprintf(stderr, "xdecode: type = %d\n", type);
  142. +        cant("happen", "type", 1);
  143. +        /* NOTREACHED */
  144. +    }
  145. +
  146. +    return ret;
  147. +}
  148. +
  149. +static int
  150. +decode2(char *ibuf, char *obuf)
  151. +{
  152. +    int n, code1, code2;
  153. +    char *ip, *op;
  154. +
  155. +    ip = ibuf;
  156. +    op = obuf;
  157. +
  158. +    n = 0;
  159. +    while (*ip != '\0') {
  160. +        if ((code1 = search_table(ip[0], ip[1])) < 0) {
  161. +            return -1;
  162. +        }
  163. +        if ((code2 = search_table(ip[2], ip[3])) < 0) {
  164. +            return -1;
  165. +        }
  166. +        ip += 4;
  167. +        *op++ = (char) (code1 * 64 + code2);
  168. +        n++;
  169. +    }
  170. +
  171. +    return n;
  172. +}
  173. +
  174. +static int
  175. +decode3(char *ibuf, char *obuf)
  176. +{
  177. +    int len, n;
  178. +    int code1, code2, code3, code4;
  179. +    char *ip, *op;
  180. +
  181. +    len = strlen(ibuf);
  182. +    ip = ibuf;
  183. +    op = obuf;
  184. +
  185. +    n = 0;
  186. +    while (len >= 8) {
  187. +        if ((code1 = search_table(ip[0], ip[1])) < 0) {
  188. +            return -1;
  189. +        }
  190. +        if ((code2 = search_table(ip[2], ip[3])) < 0) {
  191. +            return -1;
  192. +        }
  193. +        if ((code3 = search_table(ip[4], ip[5])) < 0) {
  194. +            return -1;
  195. +        }
  196. +        if ((code4 = search_table(ip[6], ip[7])) < 0) {
  197. +            return -1;
  198. +        }
  199. +        len -= 8;
  200. +        ip += 8;
  201. +        *op++ = (char) (code1 * 4 + (code2 & 0x30) / 16);
  202. +        *op++ = (char) ((code2 * 16 + (code3 & 0x3c) / 4) & 255);
  203. +        *op++ = (char) ((code3 * 64 + code4) & 255);
  204. +        n += 3;
  205. +    }
  206. +    if (len == 6) {
  207. +        if ((code1 = search_table(ip[0], ip[1])) < 0) {
  208. +            return -1;
  209. +        }
  210. +        if ((code2 = search_table(ip[2], ip[3])) < 0) {
  211. +            return -1;
  212. +        }
  213. +        if ((code3 = search_table(ip[4], ip[5])) < 0) {
  214. +            return -1;
  215. +        }
  216. +        len -= 6;
  217. +        ip += 6;
  218. +        *op++ = (char) (code1 * 4 + code2 / 16);
  219. +        *op++ = (char) ((code2 * 16 + code3 / 4) & 255);
  220. +        n += 2;
  221. +    } else if (len == 4) {
  222. +        if ((code1 = search_table(ip[0], ip[1])) < 0) {
  223. +            return -1;
  224. +        }
  225. +        if ((code2 = search_table(ip[2], ip[3])) < 0) {
  226. +            return -1;
  227. +        }
  228. +        len -= 4;
  229. +        ip += 4;
  230. +        *op++ = (char) (code1 * 4 + code2 / 16);
  231. +        n += 1;
  232. +    } else if (len != 0) {
  233. +        return -1;
  234. +    }
  235. +
  236. +    return n;
  237. +}
  238. +
  239. +typedef struct {
  240. +    char *fish_char;
  241. +    int fish_value;
  242. +} fish_t;
  243. +
  244. +fish_t fish_table[] = {
  245. +    { "ê▒", 0x00, },
  246. +    { "ê╝", 0x01, },
  247. +    { "ê±", 0x02, },
  248. +    { "ëV", 0x03, },
  249. +    { "èé", 0x04, },
  250. +    { "èÅ", 0x05, },
  251. +    { "ï¢", 0x06, },
  252. +    { "î~", 0x07, },
  253. +    { "î∩", 0x08, },
  254. +    { "ì°", 0x09, },
  255. +    { "ÄI", 0x0a, },
  256. +    { "ÄL", 0x0b, },
  257. +    { "æΓ", 0x0c, },
  258. +    { "ÆL", 0x0d, },
  259. +    { "òh", 0x0e, },
  260. +    { "ò⌐", 0x0f, },
  261. +    { "ûÄ", 0x10, },
  262. +    { "ûÉ", 0x11, },
  263. +    { "ÿk", 0x12, },
  264. +    { "Θ╡", 0x13, },
  265. +    { "Θ╢", 0x14, },
  266. +    { "Θ╖", 0x15, },
  267. +    { "Θ╕", 0x16, },
  268. +    { "Θ╣", 0x17, },
  269. +    { "Θ║", 0x18, },
  270. +    { "Θ╗", 0x19, },
  271. +    { "Θ╝", 0x1a, },
  272. +    { "Θ╜", 0x1b, },
  273. +    { "Θ╛", 0x1c, },
  274. +    { "Θ┐", 0x1d, },
  275. +    { "Θ└", 0x1e, },
  276. +    { "Θ┴", 0x1f, },
  277. +    { "Θ┬", 0x20, },
  278. +    { "Θ├", 0x21, },
  279. +    { "Θ─", 0x22, },
  280. +    { "Θ┼", 0x23, },
  281. +    { "Θ╞", 0x24, },
  282. +    { "Θ╟", 0x25, },
  283. +    { "Θ╚", 0x26, },
  284. +    { "Θ╔", 0x27, },
  285. +    { "Θ╩", 0x28, },
  286. +    { "Θ╦", 0x29, },
  287. +    { "Θ╠", 0x2a, },
  288. +    { "Θ═", 0x2b, },
  289. +    { "Θ╬", 0x2c, },
  290. +    { "Θ╧", 0x2d, },
  291. +    { "Θ╨", 0x2e, },
  292. +    { "Θ╤", 0x2f, },
  293. +    { "Θ╥", 0x30, },
  294. +    { "Θ╙", 0x31, },
  295. +    { "Θ╘", 0x32, },
  296. +    { "Θ╒", 0x33, },
  297. +    { "Θ╓", 0x34, },
  298. +    { "Θ╫", 0x35, },
  299. +    { "Θ╪", 0x36, },
  300. +    { "Θ┘", 0x37, },
  301. +    { "Θ┌", 0x38, },
  302. +    { "Θ█", 0x39, },
  303. +    { "Θ▄", 0x3a, },
  304. +    { "Θ▌", 0x3b, },
  305. +    { "Θ▐", 0x3c, },
  306. +    { "Θ▀", 0x3d, },
  307. +    { "Θα", 0x3e, },
  308. +    { "Θß", 0x3f, },
  309. +    { "ΘΓ", 0x40, },
  310. +    { "Θπ", 0x41, },
  311. +    { "ΘΣ", 0x42, },
  312. +    { "Θσ", 0x43, },
  313. +    { "Θµ", 0x44, },
  314. +    { "Θτ", 0x45, },
  315. +    { "üÅ", 0x00, },
  316. +    { "üÉ", 0x01, },
  317. +    { "üë", 0x02, },
  318. +    { "üè", 0x03, },
  319. +    { "ü`", 0x04, },
  320. +    { "ü[", 0x05, },
  321. +    { "üE", 0x06, },
  322. +    { "âA", 0x07, },
  323. +    { "âC", 0x08, },
  324. +    { "âE", 0x09, },
  325. +    { "âG", 0x0a, },
  326. +    { "âI", 0x0b, },
  327. +    { "âJ", 0x0c, },
  328. +    { "âL", 0x0d, },
  329. +    { "âN", 0x0e, },
  330. +    { "âP", 0x0f, },
  331. +    { "âR", 0x10, },
  332. +    { "âT", 0x11, },
  333. +    { "âV", 0x12, },
  334. +    { "âX", 0x13, },
  335. +    { "âZ", 0x14, },
  336. +    { "â\", 0x15, },
  337. +    { "â^", 0x16, },
  338. +    { "â`", 0x17, },
  339. +    { "âc", 0x18, },
  340. +    { "âe", 0x19, },
  341. +    { "âg", 0x1a, },
  342. +    { "âi", 0x1b, },
  343. +    { "âj", 0x1c, },
  344. +    { "âk", 0x1d, },
  345. +    { "âl", 0x1e, },
  346. +    { "âm", 0x1f, },
  347. +    { "ân", 0x20, },
  348. +    { "âq", 0x21, },
  349. +    { "ât", 0x22, },
  350. +    { "âw", 0x23, },
  351. +    { "âz", 0x24, },
  352. +    { "â}", 0x25, },
  353. +    { "â~", 0x26, },
  354. +    { "âÇ", 0x27, },
  355. +    { "âü", 0x28, },
  356. +    { "âé", 0x29, },
  357. +    { "âä", 0x2a, },
  358. +    { "âå", 0x2b, },
  359. +    { "âê", 0x2c, },
  360. +    { "âë", 0x2d, },
  361. +    { "âè", 0x2e, },
  362. +    { "âï", 0x2f, },
  363. +    { "âî", 0x30, },
  364. +    { "âì", 0x31, },
  365. +    { "âÅ", 0x32, },
  366. +    { "âÆ", 0x33, },
  367. +    { "âô", 0x34, },
  368. +    { "â@", 0x35, },
  369. +    { "âB", 0x36, },
  370. +    { "âD", 0x37, },
  371. +    { "âF", 0x38, },
  372. +    { "âH", 0x39, },
  373. +    { "âb", 0x3a, },
  374. +    { "ââ", 0x3b, },
  375. +    { "âà", 0x3c, },
  376. +    { "âç", 0x3d, },
  377. +    { "üJ", 0x3e, },
  378. +    { "üK", 0x3f, },
  379. +    { NULL, 0xff, },
  380. +};
  381. +
  382. +#define HASH_KEY  255
  383. +
  384. +typedef struct _hash_t {
  385. +    fish_t *fish;
  386. +    struct _hash_t *next;
  387. +} hash_t;
  388. +
  389. +static hash_t *hash_table[HASH_KEY + 1];
  390. +
  391. +static void
  392. +initialize_hash(void)
  393. +{
  394. +    int i;
  395. +    fish_t *fish;
  396. +    hash_t **hash;
  397. +
  398. +    for (fish = fish_table; fish->fish_char != NULL; fish++) {
  399. +        i = (fish->fish_char[0] ^ fish->fish_char[1]) & HASH_KEY;
  400. +
  401. +        hash = &hash_table[i];
  402. +        while (*hash != NULL) {
  403. +            hash = &((*hash)->next);
  404. +        }
  405. +        *hash = xmalloc(sizeof(hash_t));
  406. +        (*hash)->fish = fish;
  407. +        (*hash)->next = NULL;
  408. +    }
  409. +}
  410. +
  411. +static int
  412. +search_table(int c1, int c2)
  413. +{
  414. +
  415. +    int i;
  416. +    hash_t *hash;
  417. +
  418. +    i = (c1 ^ c2) & HASH_KEY;
  419. +
  420. +    for (hash = hash_table[i]; hash != NULL; hash = hash->next) {
  421. +        if ((char) c1 == hash->fish->fish_char[0]
  422. +            && (char) c2 == hash->fish->fish_char[1]) {
  423. +            return hash->fish->fish_value;
  424. +        }
  425. +    }
  426. +    return -1;
  427. +}
  428. +
  429. +static void *
  430. +xmalloc(int size)
  431. +{
  432. +    void *p;
  433. +
  434. +    if ((p = malloc(size)) == NULL) {
  435. +        fprintf(stderr, "%s: memory exhausted.\n", prog_name);
  436. +        exit(1);
  437. +    }
  438. +    return p;
  439.  }
  440.  
  441.  #if !HUMAN
  442. --- ..\uudx\makefile    Thu Dec 03 14:02:52 1992
  443. +++ makefile    Sat Dec 05 20:19:34 1992
  444. @@ -1,5 +1,5 @@
  445.  #
  446. -# Makefile for UUDX.EXE
  447. +# Makefile for DEFISHX.EXE
  448.  #
  449.  
  450.  MODEL          = C
  451. @@ -10,11 +10,11 @@
  452.  LDFLAGS          = -A$(MODEL)
  453.  FOO          = /link /st:0x2000
  454.  
  455. -PROGRAM          = uudx.exe
  456. -SRCS          = uudx.c \
  457. +PROGRAM          = defishx.exe
  458. +SRCS          = defishx.c \
  459.          xargs1.c \
  460.          getopt.c
  461. -OBJS          = uudx.obj \
  462. +OBJS          = defishx.obj \
  463.          xargs1.obj \
  464.          getopt.obj
  465.  
  466.